#include "SingletonStatic.h"
#include <QDebug>

#include "UI/ModRun/Output/FactoryOutput.h"

//初始化;
std::unique_ptr<SingletonStatic> SingletonStatic::Singleton::m_pInstance;

//静态类构造;
SingletonStatic::Singleton::Singleton()
{
    QString strOutput = "单例模式:内部类:构造";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }

    //初始化;
    m_pInstance.reset(new SingletonStatic());

}

SingletonStatic::Singleton::~Singleton()
{
    QString strOutput = "单例模式:内部类:析构";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

SingletonStatic::SingletonStatic()
{
    QString strOutput = "单例模式:静态类:构造";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

SingletonStatic::~SingletonStatic()
{
    QString strOutput = "单例模式:静态类:析构";
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}

//获取单例;
SingletonStatic* SingletonStatic::GetInstance()
{
    static SingletonStatic::Singleton single;
    return single.m_pInstance.get();
    //if (!m_pInstance)
    //{
    //    qDebug() << "单例模式:静态类:m_pInstance为空，错误";
    //}
    //return m_pInstance.get();
}

/// <summary>
/// 其他接口;
/// </summary>
void SingletonStatic::Display()
{
    QString strThis = QString::number(reinterpret_cast<quintptr>(this), 16);
    QString strOutput = "单例模式:静态类:Display " + strThis;
    qDebug() << strOutput;
    std::shared_ptr<IOutput> pOutPut = FactoryOutput::GetInstance()->CreateRunOutput();
    if (pOutPut)
    {
        std::initializer_list<QString> outList{ strOutput };
        pOutPut->OutPut(outList);
    }
}
